package com.spring.controller.javastack.request;

import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import java.io.Closeable;
import java.io.IOException;
import java.util.UUID;

/**
 * Created by chenhs on 2018/6/12.
 *
 * https://mp.weixin.qq.com/s/3kXSNIOiP_bKjXWA82Nvgw
 * Spring中获取Request的几种方法及其线程安全性分析
 *
 */
public class TestFetchRequest {

    public static void main(String[] args) {

        String prefix = UUID.randomUUID().toString().replaceAll("-", "") + "::";

        for (int i = 0; i < 1000; i++) {
            final String value = prefix + i;

            new Thread() {
                @Override
                public void run() {
                    try {
                        CloseableHttpClient httpClient = HttpClients.createDefault();
                   //     HttpGet httpGet = new HttpGet("http://localhost:8080/fetch/test.do?key=" + value);
                   //     HttpGet httpGet = new HttpGet("http://localhost:8080/fetch2/test2.do?key=" + value);
                        HttpGet httpGet = new HttpGet("http://localhost:8080/fecth4/test4.do?key=" + value);
                        httpClient.execute(httpGet);
                        httpClient.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }.start();

        }

    }
}
